const app = getApp();
Page({
  data: {
    StatusBar: app.globalData.StatusBar,
    CustomBar: app.globalData.CustomBar,
    web_info:app.globalData.web_info
  },

  to_index:function(){
    wx.navigateTo({
      url: '../index/index'
    })
  },

  bindGetUserInfo:function(e){
    var _this = this;
    wx.showToast({
        title: '登陆请求发送中',
        icon: 'none',
        duration: 2000
    })
      wx.login({
        success: function(res){
          var code = res.code;  //获取code
          wx.getUserInfo({  //得到rawData, signatrue, encryptData
            success: function(data){
              var rawData = data.rawData;
              var signature = data.signature;
              var encryptedData = data.encryptedData; 
              var iv = data.iv;
              wx.request({
                url: app.api_root+'api/Wxlogic/login',
                data: {
                  "code" : code,
                  "rawData" : rawData,
                  "signature" : signature,
                  'iv' : iv,
                  'encryptedData': encryptedData,
                  'inviteCode': wx.getStorageSync("inviteCode")
                },
                method: 'POST', 
                success: function(result){
                  if(result.data.code == 200){
                    wx.setStorageSync('token',result.data.data.token);
                    wx.setStorageSync('userInfo',rawData);
                    _this.setData({
                      userInfo:rawData,
                      is_login:true
                    })
                    setTimeout(function () {
                      wx.navigateBack({
                        delta: 1
                      })
                    }, 1500)
                  }
                  wx.showToast({
                    title: result.data.msg,
                    icon: 'none',
                    duration: 2000
                  })
                }
              })
            }
          })
        },
      })
  },
});
